<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<p>明天放假</p>
	<script type="text/javascript">
		var p = document.querySelector('p')

		// p.addEventListener('click', torr, true)
		function addEvent(element, eventType, fn){
				// 传统方式  p.onclick = fn
			// element['on' + eventType] = fn
			console.log(element.attachEvent)
			console.log(element.addEventListener)

			if(element.addEventListener){

				element.addEventListener(eventType, fn)
			}else if(element.attachEvent){
				// ie8及以下兼容
				element.attachEvent('on' + eventType, fn)
			}else{
				// 传统方式  p.onclick = fn
				//如果对象点的是个变量，用中括号
				element['on' + eventType] = fn
			}
		}

		addEvent(p, 'click', function(){
			console.log("放假")
		})

		let obj = {
			name:"占山"
		}
		console.log(obj.name)//占山
		let a = "name"
		console.log(obj.a)//undefined  店后面都按字符串处理，不会解析变量
	console.log(obj[a])//占山  需要解析变量 放中括号里
</html>